public class MySqrt {
    public static void main(String[] args) {
        MySqrt mySqrt = new MySqrt();
        int i = mySqrt.mySqrt(2147395599);
        System.out.println(i);
    }
    public int mySqrt(int x) {
        //采用二分法
        int left= 0;
        int right = x;
        while(left<=right){
            int mid = (left+right)/2;
            long pow = mid*mid;
            System.out.println(pow);
            if( pow ==x){
                return mid;
            }
            if(pow>x){
                right = mid -1;
            }else{
                left = mid+1;
            }
        }
        return right;
    }
}
